package no.hig.imt4721.template;

import java.util.List;

import no.hig.imt4721.model.Repetition;
import no.hig.imt4721.model.Session;
import no.hig.imt4721.model.Subject;
import no.hig.imt4721.model.Template;

public class TemplateCreatorMean extends TemplateCreator
{	
	public TemplateCreatorMean(int sessionsToDisregard, int sessionsForTemplate, int repetitionsForTemplate)
	{
		super(sessionsToDisregard, sessionsForTemplate, repetitionsForTemplate);
	}
	
	public void calculate(List<Subject> subjects)
	{
		splitData(subjects);

		// Create template
		for(Subject subject : getTemplateData())
		{
			double[] sumOfValues = new double[subject.getSessions().get(0).getRepetitions().get(0).getLengthOfRow()];
			double numberOfValues = 0;
			
			for(Session session : subject.getSessions())
			{
				for(Repetition repetition : session.getRepetitions())
				{
					for(int i = 0; i < repetition.getLengthOfRow(); i++)
					{
						sumOfValues[i] += repetition.getRowElement(i);
					}
					numberOfValues++;
				}
			}
			
			Template template = new Template();
			
			for(int i = 0; i < subject.getSessions().get(0).getRepetitions().get(0).getLengthOfRow(); i++)
			{
				template.addValue(sumOfValues[i] / numberOfValues);
			}
			
			templates.add(template);
		}
		//System.out.println("Creating Template stopped");
	}
}
